Public Class frmLastFMLogin
    Dim savedPassMD5 As String = ""
    Public Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim passMD5 = frmMain.myLastFMclient.CreateMD5(PasswordTextBox.Text)
        If PasswordTextBox.Text = "*saved*" And savedPassMD5.Length > 1 Then passMD5 = savedPassMD5
        If CheckBox1.Checked And UsernameTextBox.Text <> "*******" Then
            If frmMain.myLastFMclient.Handshake(UsernameTextBox.Text, passMD5) = False Then
                MsgBox("Error Logging In. Please check your username and password.")
                Exit Sub
            End If
            Debug.Print("Handshake Successful")
            If chkSave.Checked Then
                SaveSetting("NovaApp", "Last.fm", "Username", UsernameTextBox.Text)
                SaveSetting("NovaApp", "Last.fm", "Password", passMD5)
                SaveSetting("NovaApp", "Last.fm", "Enabled", "1")
            Else
                SaveSetting("NovaApp", "Last.fm", "Username", "")
                SaveSetting("NovaApp", "Last.fm", "Password", "")
            End If
        Else
            frmMain.myLastFMclient.ClearVars()
            SaveSetting("NovaApp", "Last.fm", "Enabled", "0")
        End If
        If chkMSNNova.Checked Then
            SaveSetting("NovaApp", "MSNNP", "AddNova", "1")
            frmMain.preMSNStr = "Nova 100: "
        Else
            SaveSetting("NovaApp", "MSNNP", "AddNova", "0")
            frmMain.preMSNStr = ""
        End If
        Me.Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Public Sub frmLastFMLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CheckBox1.Checked = frmMain.myLastFMclient.IsReady()
        UsernameTextBox.Text = GetSetting("NovaApp", "Last.fm", "Username", UsernameTextBox.Text)
        If frmMain.myLastFMclient.IsReady = True And UsernameTextBox.Text = "" Then
            UsernameTextBox.Text = "*******"
            PasswordTextBox.Text = "*saved*"
        End If
        savedPassMD5 = GetSetting("NovaApp", "Last.fm", "Password", "")
        If savedPassMD5.Length > 2 Then
            PasswordTextBox.Text = "*saved*"
            chkSave.Checked = True
            CheckBox1.Checked = GetSetting("NovaApp", "Last.fm", "Enabled", "0")
        Else
            If frmMain.myLastFMclient.IsReady = True Then
                PasswordTextBox.Text = "*******"
            Else
                PasswordTextBox.Text = ""
            End If
        End If

        chkMSNNova.Checked = GetSetting("NovaApp", "MSNNP", "AddNova", "1")
    End Sub
End Class
